<jsp:useBean id="register" class="dasregistry.registryBean" scope="session"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasCoordinateSystem"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasSource"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.Das1Source"/>
<jsp:directive.page import="org.biojava.services.das.registry.DasRegistrySql"/>
<jsp:directive.page import="org.biojava.dasobert.das.DasSpec" />
<jsp:directive.page import="org.springframework.beans.factory.BeanFactory"/>
<jsp:directive.page import="org.springframework.context.support.ClassPathXmlApplicationContext"/>
<% String title="validate DAS/1 source";
   String header = title;
   BeanFactory ctx=(new ClassPathXmlApplicationContext("SpringDAO.xml"));
		DasRegistrySql registry=(DasRegistrySql)ctx.getBean("registryBean");
%>

<%@ include file="sangerheader.jsp" %>    


<div id="main">

<h2>validate DAS source</h2>


<jsp:include page="openwindowscript.jsp" />


<%
// fed by auto id
   String aid = (String)request.getParameter("auto_id");

   String validateOntology = (String) request.getParameter("ontology");
   
   if ( validateOntology == null ) 
	   validateOntology = "";
   
   DasSource ds ;
   if ( aid != null ) {
      ds = register.getDasSource(aid);
   } else {
   	ds = new Das1Source();
	String dasurl = (String) request.getParameter("dasurl");
	if ((dasurl != null) &&  (! dasurl.equals(""))){
		ds.setUrl(dasurl);
	}
	String[] capabilities = (String[])request.getParameterValues("capabilities");
	if ( capabilities != null) {
		ds.setCapabilities(capabilities);
	}
	
	String dasSpec = (String) request.getParameter("dasSpec");
	if ((dasSpec != null) &&  (! dasSpec.equals(""))){
		ds.setSpecification(dasSpec);
	}

   }
  
   
%>



<%@ include file="sangertablestart.jsp" %>

<form action="validateAction.jsp" name="form_validate">

<tr class="row2">
	<td>DAS specification</td>
	<td><select name="spec" id="spec">
	<%
	DasSpec[] allSpecs = DasSpec.values();

	for ( int l = 0 ; l< allSpecs.length;l++){
		String specOption = allSpecs[l].toString();
		%>
		<option value="<%=specOption%>" <%
		for ( int k=0; k< allSpecs.length;k++) {
			if (ds.getSpecification().equals(specOption)){
			%>
			selected
			<%
			}
		}
		%>><%=specOption%></option>
		<%
	}
	%>
	</select>
	</td>	
	</tr>



	<tr class="row1">
	<td>url</td>
	<td><input type="input" name="dasurl" size="40" value=<%
			String u = ds.getUrl();
			if (( u==null) || (u.equals(""))){
				out.print("http://");
			} else {
				out.print(u);
			}
			%>
			/></td>	
	</tr>

	<tr class="row2">
	<td>capabilities</td>
	<td>
	 <select name="capabilities" size="3" multiple>
	<%
	 String[] all_capabilities = registry.getAllCapabilities();
	 String[] caps = ds.getCapabilitiesAsStringArray();

	 for (int i=0;i<all_capabilities.length;i++){ 
	    out.print("<option  ") ;
	    
	    
	    out.print(" value=\""+all_capabilities[i]+ "\"");
	    for ( int j=0;j< caps.length;j++) {
	    	if ( caps[j].equals(all_capabilities[i])) {
			out.print(" selected ");
		}
	    }

	    out.println(">"+all_capabilities[i]+"</OPTION>") ; 
		   
	  }	 
	 %>
	 </select>
	 </td>
	</tr>


	<tr class="row1">
	<td>test accession code / segment id</td>
	<td>
	<input type="input" name="testcode" size="20"
	<%	
		String tc = "";
		String testCode = (String) request.getParameter("testCode");

		if ( ( testCode != null ) && ( ! testCode.equals(""))) 
		   tc = testCode;
		else {
		     DasCoordinateSystem[] coords = ds.getCoordinateSystem();
		     if ( coords.length > 0) 
		     	tc = coords[0].getTestCode();
		     
		}

		if (( tc != null )&& (! tc.equals(""))) {
		out.print("value="+tc);
		}
	%>
	/> e.g. 22:19173435,19372173 for chromosome 22 and region in bp. See example links below.
	</td>
	</tr>
	
	<tr class="row2">
	<td>test correct usage of <a href="extension_ontology.jsp">Annotation type ontology</a>	 
	</td>
	<td>
	<input type="checkbox" name="ontology" <%if (validateOntology.equals("validate")){ out.print("checked"); } %> />
	</td>
	</tr>
	
	<tr class="row1">
	<td colspan="2">
	<input type="hidden"  name="auto_id" value=<%=aid %>>
	<input type="submit" value="validate">
	</td>
	</tr>

</form>

<%@ include file="sangertableend.jsp" %>


<br/>
<br/>
<ul>
<li>Show me a genomic <a href="validateServer.jsp?auto_id=DS_550">example request + validation</a></li>
<li>Show me a protein <a href="validateServer.jsp?auto_id=DS_409">example request + validation</a></li>
<li>I need some <a href="help_validation.jsp">help about validation</a></li>
<%-- <li>to validate a DAS/2 server please proceed <a href="validateServer2.jsp">here</a></li> --%>

</ul>


</div>

<%@ include file="sangerfooter.jsp" %>


